from rest_framework import serializers
from apps.goods.models import *

# SPU商品的序列化器
class SPUModelSerializer(serializers.ModelSerializer):
    brand = serializers.StringRelatedField() # 前端需要名字
    brand_id = serializers.IntegerField() # 默认是read_only = True : 只参与序列化，现在两个都参与
    category1_id = serializers.IntegerField()# 默认是read_only = True : 只参与序列化，现在两个都参与
    category2_id = serializers.IntegerField()
    category3_id = serializers.IntegerField()
    class Meta:
        model = SPU
        fields = ['id', 'name', 'brand', 'brand_id', 'category1_id', 'category2_id', 'category3_id', 'sales', 'comments', 'desc_detail', 'desc_pack', 'desc_service']


# 品牌模型类的序列化器
class BrandSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Brand
        fields =["id", "name"]


# 商品分类表的序列化器
class SPUCateSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsCategory
        fields = ["id", "name"]

